package w83b.w83bOperacionesPaso.w83bActas;

import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONObject;

import w83b.w83bDAO.w83bConstantesBD.W83bCentroTrabajoBD;
import w83b.w83bDAO.w83bConstantesBD.W83bPreavisosBD;

import es.ejie.frmk.presentacion.operacion.paso.Q70ActionPasoOP;
import es.ejie.frmk.presentacion.sesiondatos.Q70ContextoEJIE;

// TODO: Auto-generated Javadoc
/**
 * The Class W83bTablaAgrupacionesOP.java.
 *
 * @author Deusto Sistemas
 */
public class W83bTablaActasPreavisoOutOPAction extends Q70ActionPasoOP{

	
	protected void processOP(Q70ContextoEJIE contexto, ActionErrors errores, ActionMapping mapping,
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		//Guardamos la accion en el contexto
	}

	protected ActionForward processForward(Q70ContextoEJIE contexto, ActionErrors errors, ActionMapping mapping, 
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
			JSONObject jsonObject = new JSONObject();
				jsonObject.put("existe", "no");
				if(contexto.get("w83bListaPreavisos")!=null&&((List)contexto.get("w83bListaPreavisos")).size()>0){
						HashMap preaviso=(HashMap)((List)contexto.get("w83bListaPreavisos")).get(0);
						jsonObject.put("codigo",preaviso.get(W83bCentroTrabajoBD.codigoCentro));
						jsonObject.put("cif",preaviso.get(W83bCentroTrabajoBD.codNifCif));
						jsonObject.put("num",preaviso.get(W83bCentroTrabajoBD.ncentroTrab));
						jsonObject.put("razon",preaviso.get(W83bCentroTrabajoBD.razonSocial));
						jsonObject.put("prov",preaviso.get(W83bCentroTrabajoBD.codProvinciaCentro));
						jsonObject.put("mun",preaviso.get(W83bCentroTrabajoBD.codMunicipioCentro));
						jsonObject.put("hom","0");
						if(preaviso.get(W83bCentroTrabajoBD.nTrabHombres)!=null&&StringUtils.isNotEmpty(((BigDecimal)preaviso.get(W83bCentroTrabajoBD.nTrabHombres)).toString())){
							jsonObject.put("hom",preaviso.get(W83bCentroTrabajoBD.nTrabHombres));
						}
						jsonObject.put("muj","0");
						if(preaviso.get(W83bCentroTrabajoBD.nTrabMujeres)!=null&&StringUtils.isNotEmpty(((BigDecimal)preaviso.get(W83bCentroTrabajoBD.nTrabMujeres)).toString())){
							jsonObject.put("muj",preaviso.get(W83bCentroTrabajoBD.nTrabMujeres));
						}
						jsonObject.put("tot",preaviso.get(W83bCentroTrabajoBD.nTrabajadores));
						jsonObject.put("parcial",preaviso.get(W83bPreavisosBD.s_parcial_037));
						if(((String[])((String)preaviso.get("ACTA")).split("/")).length==3){
							jsonObject.put("actaPreaviso",preaviso.get("ACTA"));
						}
						else{
							jsonObject.put("actaPreaviso","");
						}
						if(null!=preaviso.get(W83bCentroTrabajoBD.codigoConvenio)){
							jsonObject.put("convenio", preaviso.get(W83bCentroTrabajoBD.codigoConvenio));
						}else{
							jsonObject.put("convenio", "");
						}
						jsonObject.put("existe", "si");
					}
				response.setContentType("text/javascript;charset=iso-8859-1");
				response.setHeader("Pragma", "cache");
				response.setHeader("Expires", "0");
				response.setHeader("Cache-Control", "private");
				response.setStatus(HttpServletResponse.SC_OK);
				PrintWriter out = response.getWriter();
				out.print(jsonObject.toString());
				out.flush();
		
		
		return null;
	}
	


}
